﻿// IntegralResultWnd.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "IntegralResultWnd.h"


// CIntegralResultWnd

IMPLEMENT_DYNCREATE(CIntegralResultWnd, CFormView)

CIntegralResultWnd::CIntegralResultWnd()
	: CFormView(IDD_CIntegralResultWnd)
{

}

CIntegralResultWnd::~CIntegralResultWnd()
{
	m_Grid.DestroyWindow();
}

void CIntegralResultWnd::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_GridControl(pDX, IDC_GRID, m_Grid);
}

BEGIN_MESSAGE_MAP(CIntegralResultWnd, CFormView)
	ON_WM_PAINT()
	ON_WM_SIZE()
END_MESSAGE_MAP()


// CIntegralResultWnd 诊断

#ifdef _DEBUG
void CIntegralResultWnd::AssertValid() const
{
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CIntegralResultWnd::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CIntegralResultWnd 消息处理程序
BOOL CIntegralResultWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
	// TODO: 在此添加专用代码和/或调用基类

	return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

void CIntegralResultWnd::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	// TODO: 在此添加专用代码和/或调用基类
	InitGrid();
}

void CIntegralResultWnd::InitGrid()
{
	m_Grid.SetFont(&gl.m_pFont);
	//标定表格
	CString strTemp;
	m_Grid.SetFixedRowCount(3);
	m_Grid.SetFixedColumnCount(1);

	m_Grid.SetRowCount(10);
	m_Grid.SetColumnCount(5);
	m_Grid.SetItemText(0, 0, TEXT("时间"));		//
	m_Grid.SetItemText(0, 3, TEXT("迟到井深(m)"));	//
	m_Grid.SetItemText(1, 0, TEXT("全烃"));	//
	m_Grid.SetItemText(1, 3, TEXT("CO2"));	//

	m_Grid.SetItemText(2, 0, TEXT("组份"));		//
	m_Grid.SetItemText(2, 1, TEXT("时间(S)"));	//
	m_Grid.SetItemText(2, 2, TEXT("峰高(mV)"));	//
	m_Grid.SetItemText(2, 3, TEXT("峰面积(mVS)"));	//
	m_Grid.SetItemText(2, 4, TEXT("浓度(%)"));	//
	for (int i = 0; i < 2; i++)
	{
		if (i % 2 == 0)
		{
			for (int k = 0; k < 5; k++)
				m_Grid.SetItemBkColour( i, k, RGB(167, 167, 211));
		}
		else
		{
			for (int k = 0; k < 5; k++)
				m_Grid.SetItemBkColour(i, k, RGB(185, 255, 255));
		}
	}
	m_Grid.SetItemBkColour(0, 0, RGB(210, 210, 210));
	m_Grid.SetItemBkColour(0, 3, RGB(210, 210, 210));
	m_Grid.SetItemBkColour(1, 0, RGB(210, 210, 210));
	m_Grid.SetItemBkColour(1, 3, RGB(210, 210, 210));
	m_Grid.SetItemBkColour(0, 1, RGB(255, 255, 255));
	m_Grid.SetItemBkColour(0, 2, RGB(255, 255, 255));
	m_Grid.SetItemBkColour(0, 4, RGB(255, 255, 255));
	for (int k = 0; k < 5; k++)
		m_Grid.SetItemBkColour(2, k, RGB(210, 210, 210));

	CRect rect;
	GetClientRect(rect);
	m_Grid.MoveWindow(rect);
    m_Grid.SetScrollRange(SB_VERT, 0, 70, TRUE);
    m_Grid.SetScrollRange(SB_HORZ, 0, 100, TRUE);

	int nRowHeight=rect.Height()/10-1;
	m_Grid.SetRowHeight(0,  nRowHeight);
	m_Grid.SetRowHeight(1, nRowHeight );
	m_Grid.SetRowHeight(2, nRowHeight );

	for (int i = 0; i < 7; i++)
	{
		m_Grid.SetRowHeight(3+i, nRowHeight );
		m_Grid.SetItemText(3+i, 0, gl.gcCi.scA[i].strName );
		m_Grid.SetItemBkColour(3 + i, 0, RGB(210, 210, 210));
		if (i % 2 == 0)
		{
			for (int k = 1; k < 5; k++)
				m_Grid.SetItemBkColour(3+i, k, RGB(167,167,211));
		}
		else
		{
			for (int k = 1; k < 5; k++)
				m_Grid.SetItemBkColour(3+i, k, RGB(185, 255, 255));
		}
	}
	m_Grid.SetColumnWidth(0, rect.Width()*60/445);
	m_Grid.SetColumnWidth(1, rect.Width()*80/445);
	m_Grid.SetColumnWidth(2, rect.Width()*85/445);
	m_Grid.SetColumnWidth(3, rect.Width()*110/445);
	m_Grid.SetColumnWidth(4, rect.Width()*80/445);
	m_Grid.Invalidate();
}

void	CIntegralResultWnd::UpdateGrid(Chrom_File curFile)
{
	CString strTemp;
	CTime tF = CTime(curFile.lTime);
	m_Grid.SetItemText(0, 1, tF.Format(_T("%m-%d")));
	m_Grid.SetItemText(0, 2, tF.Format(_T("%H:%M:%S")));
	strTemp.Format(_T("%.1f"), curFile.dLagDepth);
	m_Grid.SetItemText(0, 4, strTemp);
	strTemp.Format(_T("%.3f"), curFile.dTGMaxSignal);
	m_Grid.SetItemText(1, 1, strTemp);
	strTemp.Format(_T("%.4f"), curFile.dTGResult);
	m_Grid.SetItemText(1, 2, strTemp);
	strTemp.Format(_T("%.2f"), curFile.dCO2Result);
	m_Grid.SetItemText(1, 4, strTemp);
	for (int i = 0; i < 7; i++)
	{
		strTemp.Format(_T("%.2f"), curFile.dPeakS[i]);
		m_Grid.SetItemText(3 + i, 1, strTemp);
		strTemp.Format(_T("%.3f"), curFile.dPeakH[i]);
		m_Grid.SetItemText(3 + i, 2, strTemp);
		strTemp.Format(_T("%.5f"), curFile.dPeakA[i]);
		m_Grid.SetItemText(3 + i, 3, strTemp);
		strTemp.Format(_T("%.4f"), curFile.dResult[i]);
		m_Grid.SetItemText(3 + i, 4, strTemp);
	}
	m_Grid.Invalidate();
}

void	CIntegralResultWnd::UpdateSpecialData(float dTGSignal, float dTG, float dCO2, float dLagDepth)
{
	CString strTemp;
	strTemp.Format(_T("%.1f"), dLagDepth);
	m_Grid.SetItemText(0, 4, strTemp);
	strTemp.Format(_T("%.4f"), dTGSignal);
	m_Grid.SetItemText(1, 1, strTemp);
	strTemp.Format(_T("%.4f"), dTG);
	m_Grid.SetItemText(1, 2, strTemp);
	strTemp.Format(_T("%.2f"), dCO2);
	m_Grid.SetItemText(1, 4, strTemp);
	m_Grid.Invalidate();
}

void CIntegralResultWnd::OnPaint()
{
	CPaintDC dc(this); // device context for painting
					   // TODO: 在此处添加消息处理程序代码
					   // 不为绘图消息调用 CFormView::OnPaint()
	CRect rect;
	GetClientRect(&rect);

	CBitmap ClientScreen, *pOldBitmap;
	CRect UpdateRect(rect);

	CDC MDC;
	MDC.CreateCompatibleDC(&dc);
	ClientScreen.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
	pOldBitmap = MDC.SelectObject(&ClientScreen);
	MDC.FillSolidRect(UpdateRect, RGB(255, 255, 255));

	Draw(&MDC, rect);

	dc.BitBlt(UpdateRect.left, UpdateRect.top,
		UpdateRect.right - UpdateRect.left,
		UpdateRect.bottom - UpdateRect.top,
		&MDC, UpdateRect.left, UpdateRect.top, SRCCOPY);
	MDC.SelectObject(pOldBitmap);

	ClientScreen.DeleteObject();
	MDC.DeleteDC();
}

void CIntegralResultWnd::Draw(CDC* pDC, CRect rt)
{
	try
	{
		DrawInBorder(pDC, rt);
		rt.DeflateRect(g_DPIScaleX, g_DPIScaleY, g_DPIScaleX, g_DPIScaleY);
		BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR2, 1);
		//BxGradientFill(pDC, rt, RGB(255,123,12),BACKCOLOR2, 1);
		rt.DeflateRect(60*g_DPIScaleX, 10*g_DPIScaleY, 10*g_DPIScaleX, 20*g_DPIScaleY);
	}
	catch (...)
	{
	}
}

void CIntegralResultWnd::OnSize(UINT nType, int cx, int cy)
{
	CFormView::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
	CRect rect;
	GetClientRect(rect);
	try
	{
		if (m_Grid.m_hWnd)
		{
			CRect rt = rect;
			m_Grid.MoveWindow(rt);
			InitGrid();
		}
	}
	catch (...)
	{
	}
}
